#![allow(dead_code)]

use axum::{
    http::Request,
    middleware::Next,
    response::{IntoResponse, Response},
};

pub fn cors_middleware() {
    // CorsLayer::new()
    //     .allow_origin("http://localhost:3000".parse::<HeaderValue>().unwrap())
    //     .allow_methods([Method::GET])
}

pub async fn demo_middleware<B>(
    request: Request<B>,
    next: Next<B>,
) -> Result<impl IntoResponse, Response> {
    let request = http_context(request).await?;
    Ok(next.run(request).await)
}

async fn http_context<B>(request: Request<B>) -> Result<Request<B>, Response> {
    let (parts, body) = request.into_parts();

    tracing::info!("demo {:?}", parts);
    Ok(Request::from_parts(parts, body))
}
